package org.zfes.snowier.common.monitor.config.ws;

import java.util.Map;

import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.http.server.ServletServerHttpRequest;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor;

public class HandShake extends HttpSessionHandshakeInterceptor  {
	
	@Override 
	public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) throws Exception { 
	    String userCode = ((ServletServerHttpRequest) request).getServletRequest().getParameter("userCode"); 
	    if(userCode!=null){ 
	    	
	      attributes.put("userCode", userCode); 
	      
	    }else{ 
	    	
	      return false; 
	      
	    } 
	    return super.beforeHandshake(request, response, wsHandler, attributes);
	  } 
	 
	  @Override 
	  public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Exception exception) { 
		  super.afterHandshake(request, response, wsHandler, exception);
	     
	  } 
}
